#ifndef _METRICS_H_
#define _METRICS_H_

#include "num/named_set.h"

namespace gameflow
{

	
struct	MetricPackage
{
	MetricPackage() 
	{	Reset(); };
	void	Reset()
	{
		Total		= 0.0f;
		ThisTurn	= 0.0f;
		Min			= 10e5;
		Max			= 0.0f;
		SamplesThisTurn = TotalSamples = 0;
	}
	std::string	Key;
	float			Total;
	float			ThisTurn;
	float			Min;
	float			Max;
	int				TotalSamples;
	int				SamplesThisTurn;
};

/***
 * Track metrics. Doesn't really know what it's tracking 
 */
class Metrics : public num::NamedSet<MetricPackage*>
{	
public:
	static Metrics& Instance();
	void		Load(const std::string& File);
	void		Save(const std::string& File);

	void		ResetKey(const std::string& Key);
	void		AccumulateKey(const std::string& Key, float Value);

	float		GetTimeStamp();
private:
	Metrics();
	~Metrics();
};

/***
 * RAII based auto-metric block
 */
class AutoMetric
{
	AutoMetric(const std::string& Key);
	~AutoMetric();
	
	float				Start;
	std::string			KeyID;
};
} // namespace gameflow

//#define _TRACK_METRICS
#ifdef  _TRACK_METRICS                
	#define ACCUMULATE_METRIC(Section, Value)		gameflow::Metrics::Instance().AccumulateKey(Section, Value);
    #define METRIC_BLOCK(Section)			gameflow::AutoMetric		TempMetricSection(Section);
#else
    #define ACCUMULATE_METRIC(Section, Value)     
    #define METRIC_BLOCK(Section)
#endif


#endif //_METRICS_H_